﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Threading.Tasks;
using VOL.Core.Utilities;
using VOL.Domain.Dto;
using VOL.Domain.IServices;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseManagementController : ControllerBase
    {
        private readonly IPurchaseReturnService purchaseReturnService;
        private readonly ISalesOutService salesOutService;

        public WarehouseManagementController(
            IPurchaseReturnService purchaseReturnService,
            ISalesOutService salesOutService)
        {
            this.purchaseReturnService = purchaseReturnService;
            this.salesOutService = salesOutService;
        }
        [HttpGet]
        public PageGridData<PurchaseReturn> GetPurchaseReturns([FromQuery]GetPurchaseReturnsDto dto)
        {
            return purchaseReturnService.GetPurchaseReturns(dto);
        }

        [HttpPost]
        public Task<WebResponseContent> AddPurchaseReturn([FromBody] PurchaseReturn entity)
        {
            return  purchaseReturnService.AddPurchaseReturn(entity);
        }

        [HttpPost]
        public Task<WebResponseContent> UpdatePurchaseReturn([FromBody] PurchaseReturn entity)
        {
            return purchaseReturnService.UpdatePurchaseReturn(entity);
        }
        /// <summary>
        /// 更新采购退货单状态
        /// </summary>
        /// <param name="id">记录ID</param>
        /// <param name="states">新状态值</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public Task<WebResponseContent> UpdatePurchaseReturnStates(int id, int states)
        {
            return purchaseReturnService.UpdatePurchaseReturnStates(id, states);
        }

        /// <summary>
        /// 批量删除采购退货单
        /// </summary>
        /// <param name="ids">待删除的记录ID数组</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public Task<WebResponseContent> BatchDeletePurchaseReturn([FromBody] int[] ids)
        {
            return purchaseReturnService.BatchDeletePurchaseReturn(ids);
        }

        /// <summary>
        /// 获取销售出库分页数据
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>分页数据</returns>
        [HttpGet]
        public async Task<PageGridData<SalesOut>> GetSalesOutPages([FromQuery] GetSalesOutDto dto)
        {
            return await salesOutService.GetSalesOutPages(dto);
        }

        /// <summary>
        /// 添加销售出库单
        /// </summary>
        [HttpPost]
        public async Task<bool> AddSalesOut([FromBody] SalesOut entity)
        {
            return await salesOutService.AddSalesOutAsync(entity);
        }

        /// <summary>
        /// 编辑销售出库单
        /// </summary>
        [HttpPost]
        public async Task<bool> UpdateSalesOut([FromBody] SalesOut entity)
        {
            return await salesOutService.UpdateSalesOutAsync(entity);
        }

        /// <summary>
        /// 修改销售出库单状态
        /// </summary>
        [HttpPost]
        public async Task<bool> UpdateSalesOutStatus(int id, int status)
        {
            return await salesOutService.UpdateSalesOutStatusAsync(id, status);
        }

        /// <summary>
        /// 批量删除销售出库单
        /// </summary>
        /// <param name="ids">待删除的记录ID数组</param>
        /// <returns>操作结果</returns>
        [HttpPost]
        public Task<WebResponseContent> BatchDeleteSalesOut([FromBody] int[] ids)
        {
            return salesOutService.BatchDeleteSalesOut(ids);
        }

        /// <summary>
        /// 查询客户信息
        /// </summary>
        /// <param name="dto">查询条件</param>
        /// <returns>客户列表</returns>
        [HttpGet]
        public async Task<PageGridData<Customer>> GetCustomerList([FromQuery] GetCustomerDto dto)
        {
            return await salesOutService.GetCustomerList(dto);
        }
    }
}
